/*
    Copyright 2000-2011 Francois de Bertrand de Beuvron

    This file is part of CoursBeuvron.

    CoursBeuvron is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CoursBeuvron is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CoursBeuvron.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.insa.beuvron.tps.m2.dessin2DV3.gui;

import fr.insa.beuvron.tps.m2.dessin2DV3.EnsembleFigure;
import fr.insa.beuvron.tps.m2.dessin2DV3.Figure;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

/**
 * un combobox pour choisir une sous-figure dans un EnsembleFigure
 * @author francois
 */


public class SousFigsCombobox extends JComboBox {
    
    private EnsembleFigure fig;
    
    public SousFigsCombobox(EnsembleFigure fig) {
        super(fromFigToComboModel(fig));
        this.fig = fig;
    }
    
    private static DefaultComboBoxModel fromFigToComboModel(EnsembleFigure fig) {
        return new DefaultComboBoxModel(fig.getLesFigs().toArray());
    }
    
    public void miseAJour() {
        this.setModel(fromFigToComboModel(this.fig));
    }

    /**
     * @return the fig
     */
    public EnsembleFigure getFig() {
        return fig;
    }

    /**
     * @param fig the fig to set
     */
    public void setFig(EnsembleFigure fig) {
        this.fig = fig;
    }
}
